<template>
    <div>
        <el-form :model="form" label-width="120px" class="demo-ruleForm">
        <div class="container">
            <h4 style="margin-bottom: 20px">{{form.breedName}}</h4>
            <el-button type="primary" v-if="form.isRecall == 0" @click="handlePrint">发送</el-button>
            <el-row>
                <el-col :span="12">
                    <el-form-item label="分包数量：">
                        {{form.printNum}}包
                    </el-form-item>
					<el-form-item label="产品大类：">
						{{form.inventoryType}}
					</el-form-item>
                    <el-form-item label="包装批号：">
                        {{form.batch}}
                    </el-form-item>
                    <el-form-item label="发药机编码：">
                        {{form.dispenserCode}}
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="已使用：">
                        {{form.weight*form.lastPrintNum}}{{form.units}}
                    </el-form-item>
                    <el-form-item label="存货代码：">
                        {{form.inventoryCode}}
                    </el-form-item>
                    <el-form-item label="状态：">
                        {{form.type == 0?'未打印':'已打印'}}<span v-if="form.type == 1">({{form.lastPrintNum}})</span>
                    </el-form-item>
                </el-col>
            </el-row>
        </div>
        <div class="container" style="margin-top: 20px">
            <h3 style="margin-bottom: 20px">打印明细</h3>
            <el-table
                :data="tableData"
                border
                ref="multipleTable"
                header-cell-class-name="table-header"
            >
                <el-table-column prop="createtime" sortable label="打印时间"></el-table-column>
                <el-table-column prop="sendAmount" sortable label="申请码数"></el-table-column>
                <el-table-column prop="userName" sortable label="申请人"></el-table-column>
                <el-table-column prop="sendStatus" sortable label="状态">
                    <template slot-scope="scope">
                        <span v-if="scope.row.sendStatus == '2' && scope.row.mongoStatus == '2'">已发送</span>
                        <span v-else-if="scope.row.sendStatus == '1' || scope.row.mongoStatus == '1'">发送失败</span>
                        <span v-else-if="scope.row.sendStatus == '0' || scope.row.mongoStatus == '0'">发送中</span>
                    </template>
                </el-table-column>
              <!--  <el-table-column prop="sendStatus" sortable label="操作">
                    <template slot-scope="scope">
                        <el-button
                            v-if="scope.row.sendStatus == '1' || scope.row.mongoStatus == '1'"
                            type="text"
                            @click="reHandlePrint(scope.$index, scope.row)"
                        >重新发送</el-button>
                    </template>
                </el-table-column> -->
            </el-table>
            <el-pagination layout="prev, pager, next" :page-size="pagesize1" @current-change="handleCurrentChange1" :total="total1" :current-page.sync="currentPage1" style="margin-top:20px"></el-pagination>
        </div>
        <el-form-item class="footerFixed">
            <el-button @click="backPage">返回</el-button>
        </el-form-item>
        </el-form>
    </div>
</template>

<script>
import {print_detail,print_resend} from "@/request/api";
import { mapState } from 'vuex';
    export default {
        components: {
        },
        data() {
            return {
                form: {},
                tableData: [],
                total1: 0,
                currentPage1:1,
                pagesize1:10,
                most: '',
                lastPrintNum: '',
                endPrintNum: 0,
            };
        },
        mounted(){
            this.id = this.$route.query.id
            this.init()
        },
        computed:{
            ...mapState(['switchHeadTab'])
        },
        methods: {
            backPage () {
                this.$router.go(-1);
            },
            init(){
                print_detail({
                    printId: this.id,
                    pageno: this.currentPage1,
                    pagesize: this.pagesize1
                }).then((res) =>{
                    this.form = res.print
                    this.tableData = res.rows
                    this.total1 = res.total
                })
            },
            // 发送
            handlePrint(){
                var endNum = this.form.printNum
                console.log(endNum,1111)
                if(this.switchHeadTab == '中药饮片'){
                    this.$router.push({
                        path: '/printTask/medicalHerbPrintTemplate',
                        query: { id: this.form.id, lastPrintNum: this.form.lastPrintNum, endNum: endNum }
                    });
                }else{
                    this.$router.push({
                        path: '/printTask/editPrint',
                        query: { id: this.form.id, lastPrintNum: this.form.lastPrintNum, endNum: endNum }
                    });
                }

            },
            // 重新发送
            reHandlePrint(index,row){
                print_resend(row.id).then((res) => {
                    this.$notify({
                        title: '提示',
                        message: '发送成功',
                        type: 'success',
                        duration:1000
                    });
                    this.init();
                })
            },
            handleCurrentChange1(val){
                this.currentPage1 = val
                this.init()
            },
        }
    }
</script>
<style scoped lang="less">
.el-pagination{
    text-align: center;
}
</style>
